﻿Public Class DataModifier

    Private _Trades As Generic.List(Of Trade)
    Public Property Trades() As Generic.List(Of Trade)
        Get
            Return _Trades
        End Get
        Set(ByVal value As Generic.List(Of Trade))
            _Trades = value
        End Set
    End Property

    Function ModifyTrades(ByVal AllTrades As Generic.List(Of Trade)) As Generic.List(Of Trade)
        Me.Trades = AllTrades
        'modifies each row depending on user preferences

        Try

            For Each aTrade As Trade In Me.Trades
                With aTrade

                    If Not My.Settings.bTradeIDInFile Then aTrade.GenerateTradeID()
                    .TrimTradeID()

                    'TODO:
                    'SellSide Check

                    'check fund & broker mapping
                    .Fund.Rename(.GivenCCY, .CounterCCY, .Broker.BrokerName)
                    Dim brkMapped As Broker = .Fund.MapBroker(.GivenCCY, .CounterCCY, .Broker.BrokerName)
                    'If brkMapped IsNot Nothing Then
                    .Broker = brkMapped
                    'Else
                    '    aTrade.Upload = False
                    'End If


                    .Fund.RemoveSpecialChars()

                    'check currency mapping - changes currencies,
                    For Each drCCYMap As dsCCYMap.CCYMapRow In My.Settings.CCYMap(0)
                        If .GivenCCY = drCCYMap.CCYFrom Then
                            .GivenCCY = drCCYMap.CCYTo
                        ElseIf .CounterCCY = drCCYMap.CCYFrom Then
                            .CounterCCY = drCCYMap.CCYTo
                        End If
                    Next

                    'Spot/Fwd
                    .GetSpotFwd()

                    'ssis & netting & ndf default - must be done before broker/fund mapping as names are changed
                    .SSIs = New SSI
                    .SSIs.GetSSIs(aTrade)

                    'account suffix/prefix
                    If My.Settings.bAcctCodePrefix Then .Fund.FundName = My.Settings.sAcctCodePrefix & .Fund.FundName
                    If My.Settings.bAcctCodeSuffix Then .Fund.FundName = .Fund.FundName & My.Settings.sAcctCodeSuffix


                End With
            Next

            Return Me.Trades

        Catch ex As Exception
            Logger.ErrorLog(ex, "Data Modification")
            End
        End Try

    End Function


End Class
